﻿CREATE FUNCTION [dbo].[NextMenusList]
( @MenuID int
)RETURNS TABLE
AS
RETURN(
SELECT TOP (100) PERCENT WorkFlowIndex, MenuID, MenuName,def
FROM(
	SELECT WorkFlowIndex,MenuID, MenuName,1 def	FROM v_Menu_10 WHERE MenuID = @MenuID
		UNION
	SELECT     NextWFIndex, NextMenuID, NextMenuName,0
	FROM         dbo.NextMenus(@MenuID,DEFAULT) WHERE NextMenuID <> @MenuID
/*

	SELECT     t_Menu.WorkFlowIndex, t_Menu.MenuID, t_Menu.MenuName,1 def
	FROM         t_Tracker INNER JOIN
												v_Menu_10 AS t_Menu ON t_Tracker.StatusID = t_Menu.MenuID
	WHERE     (t_Tracker.ID = @ID)

	UNION

	SELECT     NextWFIndex, NextMenuID, NextMenuName,0
	FROM         dbo.NextTrackerStatuses(@ID,DEFAULT)
*/
)T
ORDER BY WorkFlowIndex

)
